package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.TeacherSubject;
import com.ruoyi.system.service.ITeacherSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 教师学科Controller
 * 
 * @author bearzz
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/subject")
public class TeacherSubjectController extends BaseController
{
    @Autowired
    private ITeacherSubjectService teacherSubjectService;

    /**
     * 查询教师学科列表
     */
    @RequiresPermissions("teacher:subject:list")
    @GetMapping("/list")
    public TableDataInfo list(TeacherSubject teacherSubject)
    {
        startPage();
        List<TeacherSubject> list = teacherSubjectService.selectTeacherSubjectList(teacherSubject);
        return getDataTable(list);
    }

    /**
     * 导出教师学科列表
     */
    @RequiresPermissions("teacher:subject:export")
    @Log(title = "教师学科", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherSubject teacherSubject)
    {
        List<TeacherSubject> list = teacherSubjectService.selectTeacherSubjectList(teacherSubject);
        ExcelUtil<TeacherSubject> util = new ExcelUtil<TeacherSubject>(TeacherSubject.class);
        util.exportExcel(response, list, "教师学科数据");
    }

    /**
     * 获取教师学科详细信息
     */
    @RequiresPermissions("teacher:subject:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(teacherSubjectService.selectTeacherSubjectById(id));
    }

    /**
     * 新增教师学科
     */
    @RequiresPermissions("teacher:subject:add")
    @Log(title = "教师学科", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherSubject teacherSubject)
    {
        return toAjax(teacherSubjectService.insertTeacherSubject(teacherSubject));
    }

    /**
     * 修改教师学科
     */
    @RequiresPermissions("teacher:subject:edit")
    @Log(title = "教师学科", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherSubject teacherSubject)
    {
        return toAjax(teacherSubjectService.updateTeacherSubject(teacherSubject));
    }

    /**
     * 删除教师学科
     */
    @RequiresPermissions("teacher:subject:remove")
    @Log(title = "教师学科", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(teacherSubjectService.deleteTeacherSubjectByIds(ids));
    }
}
